Skip to content

Wrappers: export only from the DLL; optimize and section the release build - #94

Merged
ASDAlexander77 merged 1 commit into
mainfrom
binary-size
Nov 12, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
binary-size

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Why

  • src/wrappers/tslang_export.h made every wrapper __declspec(dllexport) whenever _WIN32, though its comment said it was a no-op for the static library. The same objects went into TypeScriptDefaultLib.lib, so every program exported, and therefore kept, all regexp_*, http_* and stdio_* wrappers, and wrote a .lib/.exp next to itself.
  • The release wrappers were built with /MT /std:c++latest only, with no /O2, so cl did not optimize them at all.

Changes

  • tslang_export.h: exports only under TSLANG_WRAPPERS_DLL. build_core.bat compiles the wrappers a second time with it, into <lib>\dll_wrappers, for the DLL link. The DLL export tables are unchanged (diffed, all four models, release and debug).
  • build_core.bat: release /O2 /Gy /Gw /wd4710 /wd4711, debug /Gy /Gw. The /wd flags stop /Wall from listing every inlining decision.
  • build.sh, build_android.bat: -ffunction-sections -fdata-sections, for the compiler's new --gc-sections link.

With ASDAlexander77/TypeScriptCompiler binary-size (function sections for lib.ts), a Windows -mm=own --opt program using Map/sort/toString went from 831 KB to 437 KB. The library's share went from ~500 KB to ~32 KB.

Tests

  • tests.ps1, all four models × release/debug × compile/jit: all pass, declarations match.
  • tests.sh in WSL: all pass except weakref_basic gc release, which fails on every run with the locally built libgc.a.
  • wasm defaultlib suites, release and debug: 0 failures.

🤖 Generated with Claude Code

…build

- src/wrappers/tslang_export.h exported every wrapper whenever _WIN32, though its comment said
  it was a no-op for the static library. The same objects went into TypeScriptDefaultLib.lib, so
  every program exported - and so kept - all the regexp_*, http_*, stdio_* wrappers, and wrote a
  .lib/.exp beside itself. Now only TSLANG_WRAPPERS_DLL exports; build_core.bat compiles the
  wrappers a second time with it for the DLL. The DLL export tables are unchanged (all four
  models, release and debug).
- build_core.bat: release wrappers had no /O2 at all (cl then does not optimize). Now
  /O2 /Gy /Gw (debug /Gy /Gw), so each function is a COMDAT the linker can drop; /wd4710
  /wd4711 keep /Wall from listing every inlining decision.
- build.sh, build_android.bat: -ffunction-sections -fdata-sections, for the compiler's new
  --gc-sections link.

With the compiler's matching change (function sections for lib.ts), a Windows -mm=own program
using Map/sort/toString went from 831 KB to 437 KB; the default library's share from ~500 KB to
~32 KB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 691792a into main Nov 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant